package org.pqw.bookmodel.config;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * mq 生产者
 * @author 白衣雪
 * @since 2021/6/21 22:26
 */
@Configuration
public class RocketMqConfig {

    @Resource
    private MqConfigReader reader;

    private static final String MQ_DEFAULT_GROUP = "BOOK_MODEL_GROUP";
    private static final int MQ_TIME_OUT = 30000;

    @Bean
    public DefaultMQProducer defaultProducer(){
        DefaultMQProducer defaultMqProducer = new DefaultMQProducer(MQ_DEFAULT_GROUP);
        defaultMqProducer.setNamesrvAddr(this.reader.getNameSvr());
        defaultMqProducer.setSendMessageWithVIPChannel(false);
        defaultMqProducer.setSendMsgTimeout(MQ_TIME_OUT);
        return defaultMqProducer;
    }

    @Bean
    public DefaultMQPushConsumer defaultConsumer(){
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(MQ_DEFAULT_GROUP);
        consumer.setNamesrvAddr(this.reader.getNameSvr());
        consumer.setConsumeTimeout(MQ_TIME_OUT);
        return consumer;
    }

}
